package com.hongkzh.www.view.customview;

import android.content.Context;
import android.support.v4.content.ContextCompat;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ProgressBar;
import android.widget.TextView;

import com.hongkzh.www.R;
import com.liaoinstan.springview.container.BaseFooter;

/**
 * Created by Administrator on 2016/3/21.
 * springview 自定义上拉加载
 */
public class MyFooter extends BaseFooter {
    private Context context;
    private int rotationSrc;
    private TextView footerTitle;
    private ProgressBar footerProgressbar;
    private boolean lastPage = false;

    public MyFooter(Context context) {
        this(context, R.drawable.progress_small);
    }

    public MyFooter(Context context, int rotationSrc) {
        this.context = context;
        this.rotationSrc = rotationSrc;
    }

    @Override
    public View getView(LayoutInflater inflater, ViewGroup viewGroup) {
        View view = inflater.inflate(R.layout.my_footer, viewGroup, true);
        footerTitle = view.findViewById(R.id.default_footer_title);
        footerProgressbar = view.findViewById(R.id.default_footer_progressbar);
        footerProgressbar.setIndeterminateDrawable(ContextCompat.getDrawable(context, rotationSrc));
        return view;
    }

    @Override
    public void onPreDrag(View rootView) {
    }

    @Override
    public void onDropAnim(View rootView, int dy) {
    }

    @Override
    public void onLimitDes(View rootView, boolean upORdown) {
        if (lastPage) {
            footerTitle.setText(R.string.footer_last);
        } else {
            if (upORdown) {
                footerTitle.setText(R.string.footer_body);
            } else {
                footerTitle.setText(R.string.footer_first);
            }
        }
    }

    @Override
    public void onStartAnim() {
        if (lastPage) {
            footerTitle.setVisibility(View.VISIBLE);
            footerProgressbar.setVisibility(View.GONE);
        } else {
            footerTitle.setVisibility(View.INVISIBLE);
            footerProgressbar.setVisibility(View.VISIBLE);
        }
    }

    @Override
    public void onFinishAnim() {
        if (lastPage) {
            footerTitle.setText(R.string.footer_last);
        } else {
            footerTitle.setText(R.string.footer_first);
        }
        footerTitle.setVisibility(View.VISIBLE);
        footerProgressbar.setVisibility(View.INVISIBLE);
    }

    public void setLastPage(boolean lastPage) {
        this.lastPage = lastPage;
    }
}